//          https://ac.nowcoder.com/acm/contest/11217/G





#include <iostream>
using namespace std;

int main()
{
    int n, p;
    cin >> n >> p;
    int a[n], k[n], ans = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        k[max(a[i] - p, 0)] += 1;
        k[a[i] + p + 1] -= 1;
    }

    for (int j = 1; j <= n; j++)
    {
        k[j] += k[j - 1];
        ans = max(ans, k[j]);
    }

    cout << ans << endl;
    return 0;
}